symbolicpaintable: Refactor default colors path
authorBenjamin Otte <otte@redhat.com>
Mon, 30 Aug 2021 02:56:43 +0000 (04:56 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 30 Aug 2021 03:29:04 +0000 (05:29 +0200)
gtk/gtksymbolicpaintable.c

index f33d63c837efb31eca60e09f119f4888a3d6ba5f..61bc19ab808488ab7e4f8d6299e6aa931ddab761 100644 (file)
@@ -21,6 +21,8 @@
 
 #include "gtksymbolicpaintable.h"
 
+#include "gtkenums.h"
+
 /**
  * GtkSymbolicPaintable:
  *
@@ -68,7 +70,7 @@ gtk_symbolic_paintable_default_init (GtkSymbolicPaintableInterface *iface)
  *
  * Snapshots the paintable with the given colors.
  *
- * If not at least 4 colors are provided, GTK will pad the array with default
+ * If less than 4 colors are provided, GTK will pad the array with default
  * colors.
  */
 void
@@ -97,16 +99,15 @@ gtk_symbolic_paintable_snapshot_symbolic (GtkSymbolicPaintable   *paintable,
   else
     {
       /* Taken from GTK3, no idea where it got those from */
-      GdkRGBA fg_default = { 0.7450980392156863, 0.7450980392156863, 0.7450980392156863, 1.0 };
-      GdkRGBA error_default = { 0.796887159533074, 0, 0, 1.0 };
-      GdkRGBA warning_default = {0.9570458533607996, 0.47266346227206835, 0.2421911955443656, 1.0 };
-      GdkRGBA success_default = { 0.3046921492332342,0.6015716792553597, 0.023437857633325704, 1.0 };
+      GdkRGBA real_colors[4] = {
+        [GTK_SYMBOLIC_COLOR_FOREGROUND] = { 0.7450980392156863, 0.7450980392156863, 0.7450980392156863, 1.0 },
+        [GTK_SYMBOLIC_COLOR_ERROR] = { 0.796887159533074, 0, 0, 1.0 },
+        [GTK_SYMBOLIC_COLOR_WARNING] = { 0.9570458533607996, 0.47266346227206835, 0.2421911955443656, 1.0 },
+        [GTK_SYMBOLIC_COLOR_SUCCESS] = { 0.3046921492332342,0.6015716792553597, 0.023437857633325704, 1.0 }
+      };
+
+      memcpy (real_colors, colors, sizeof (GdkRGBA) * n_colors);
 
-      iface->snapshot_symbolic (paintable, snapshot, width, height, (GdkRGBA[4]) {
-                                  n_colors > 0 ? colors[0] : fg_default,
-                                  n_colors > 1 ? colors[1] : error_default,
-                                  n_colors > 2 ? colors[2] : warning_default,
-                                  success_default,
-                                }, 4);
+      iface->snapshot_symbolic (paintable, snapshot, width, height, real_colors, 4);
     }
 }